package com.article.quartz;

import com.article.model.ArticleInfo;
import com.article.model.ArticleType;
import com.article.service.ArticleInfoService;
import com.article.service.ArticleTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * Created by Administrator on 2017/5/4.
 */
public class Refresh {
    private final static Logger logger = LoggerFactory.getLogger(Refresh.class);
    @Autowired
    private ArticleTypeService articleTypeService;
    @Autowired
    private ArticleInfoService articleInfoService;

    public void work() throws Exception {
        WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
        ServletContext application = wac.getServletContext();
        List<ArticleType> articleTypeList = articleTypeService.listCount();// 查询文章类别以及文章的数量
        application.setAttribute("articleTypeCount", articleTypeList);

        List<ArticleInfo> articleInfoList = articleInfoService.listCount();//按日期查询文章数量
        application.setAttribute("articleCount", articleInfoList);
        logger.info("刷新缓存");
    }
}
